﻿import gdca.webservice.common.GdcaCommonServiceServiceLocator;
import gdca.webservice.common.GdcaCommonServiceSoapBindingStub;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;


/**
 * 测试天翼税通
 */

/**
 * 
 */
public class TestTyst {
	static BufferedReader 	keyIn 				= null;	//读取用户输入的信息	
	static String 			schoice  			= null;	//判断用户选择的信息
	
	public static void main(String args[]) throws Exception
	{
			
		while(true)
		{
			 System.out.println("");
	         System.out.println("======================   接口例子测试  ，开始，请选择  =====================");
	         System.out.println("1. 新增          (输入 1 )                                                              ");
	         System.out.println("2. 资料更新      (输入 2 )                                                          ");   
	         System.out.println("3. 注销      (输入 3 )                                                          ");     
	         System.out.println("4. 到期更新     (输入 4 )                                                          ");     
	         System.out.println("5. 补发      (输入 5 )                                                          ");     
	         System.out.println("6. 解锁      (输入 6 )                                                          ");     
	         System.out.println("==========================================================================");
			 
	         //-------------通过判断用户录入的业务编码进行相应的业务流程操作-------------//
	         try
		      {  
		       	  System.out.print("please input your choice:");   
		       	  keyIn = new BufferedReader(new InputStreamReader(System.in));
		       	  schoice = new String(keyIn.readLine());
		      }
	         catch(Exception e)
	         {
	        	 System.out.println("您输入的选择错误！");
	        	 return ;
	         }
	         if (schoice.equals("0")) {
	        	 System.out.println("成功退出！");
	        	 return;
	         }
	         else if (schoice.equals("1")) {
	        	 test("001");//新增
	         }
	         else if (schoice.equals("2")) {
	        	 test("002");//更新
	         }	
	         else if (schoice.equals("3")) {
	        	 test("003");//注销
	         }
	         else if (schoice.equals("4")) {
	        	 test("004");//到期更新
	         }
	         else if (schoice.equals("5")) {
	        	 test("005");//补发
	         }
	         else if (schoice.equals("6")) {
	        	 test("006");//解锁
	         }
	         else
	         {
	        	 System.out.println("抱歉，您输入的选择错误，确认选择以上显示的提示信息！");
	         }		
		}
		
	}
	
	public static void test(String busyType) throws Exception
	{
		/**busyType 的选择 
		 * new      新增
		 * update   更新
		 */
		java.net.URL url = new java.net.URL("http://127.0.0.1:7001/services/GdcaCommonService");
		//java.net.URL url = new java.net.URL("http://61.142.239.157/services/GdcaCommonService");
		GdcaCommonServiceServiceLocator locator = new GdcaCommonServiceServiceLocator();
		GdcaCommonServiceSoapBindingStub stub = new GdcaCommonServiceSoapBindingStub(url, locator);
		stub.setUsername("test");
		stub.setPassword("123456");
		
		String isEnc = "0";
		String customCode = "0011";
		String signValue = "";
		String isSign = "0";
		String operData = "";
		String fileName = "tyst/new.xml";

		if(busyType.equals("001"))
		{
			fileName = "tyst/new.xml";
		}
		else if(busyType.equals("002"))
		{
			fileName = "tyst/updateInfo.xml";
		}
		else if(busyType.equals("003"))
		{
			fileName = "tyst/revoke.xml";
		}
		else if(busyType.equals("004"))
		{
			fileName = "tyst/updateDate.xml";
		}
		else if(busyType.equals("005"))
		{
			fileName = "tyst/renew.xml";
		}
		else if(busyType.equals("006"))
		{
			fileName = "tyst/unlock.xml";
		}
		Document gsDataXml = null;
		File gsDataXmlFile = new File(fileName);
		SAXReader gsDataXmlReader = new SAXReader();
		gsDataXml = gsDataXmlReader.read(gsDataXmlFile);
		operData = gsDataXml.asXML();
		
		long l = System.currentTimeMillis();
		String res = stub.gdcaBusyDeal(customCode, operData, isSign, signValue, isEnc);
		//String res = stub.gdcaBusyDealCa(customCode, operData, isSign, signValue, isEnc);
		System.out.println("调用接口，使用时间:" +  (System.currentTimeMillis() - l) + "毫秒");
		System.out.println(res);
	}
	
	
}
